import YzOperator from './yzOperator'

export default class YzDoubleOperator extends YzOperator {
  /**
   * 构造函数
   * @param {*} source 原操作对象
   * @param {*} op 操作符
   * @param {*} target 目标操作对象
   */
  constructor (source, op, target, opBefore, targetBefore) {
    super(source, op, target)
    this.targetBefore = targetBefore
    this.opBefore = opBefore
    this.type = 'double'
  }

  reverseOp (op) {
    const reverseOpMap = {
      '<': '>',
      '<=': '>=',
      '>': '<',
      '>=': '<='

    }
    if (Object.keys(reverseOpMap).includes(op)) {
      return reverseOpMap[op]
    }
    return op
  }

  getDisplayString () {
    return `${this.target.getDisplayString()} ${YzOperator.getOpDisplayString(this.reverseOp(this.op))} ${this.source.getDisplayString()} ${YzOperator.getOpDisplayString(this.opBefore)} ${this.targetBefore.getDisplayString()}`
  }

  getExecJsString () {
    return `() => {return ${this.target.getExecJsString()} ${this.op}  ${this.source.getExecJsString()} && ${this.source.getExecJsString()} ${this.opBefore} ${this.targetBefore.getExecJsString()}}`
  }
}
